/**
 * 
 */
package com.googlecode.dynargs.extractor;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.googlecode.dynargs.model.type.SimpleType;

/**
 * @author Federico De Faveri defaveri@gmail.com
 *
 */
public class JavaBaseTypesExtractor implements TypeExtractor<SimpleType> {

	protected static final Set<Class<?>> BASE_TYPE = new HashSet<Class<?>>();
	static {
		BASE_TYPE.add(String.class);
		BASE_TYPE.add(Integer.class);
		BASE_TYPE.add(Long.class);
		BASE_TYPE.add(Double.class);
		BASE_TYPE.add(Date.class);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean canExtract(TypeToken type) {
		Class<?> clazz = type.getRawType();
		if (BASE_TYPE.contains(clazz)) return true;
		return clazz.isPrimitive();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public SimpleType extract(ModelExtractor modelExtractor, TypeToken type) {
		Class<?> clazz = type.getRawType();
		return new SimpleType(clazz.getName());
	}

}
